<?php
/** 
 * Unit_patient_location_model
 * This class handles model work necessary for Unit_patient_location Crud and List operations 
 * 
 * @author Ray Nowell
 *	
 */ 
class Unit_patient_location_model extends MY_Model {

	function Unit_patient_location_model()
	{
		parent::MY_Model();
	}
	
	function Add_unit_patient_location($data)
	{
		return $this->db->insert('unit_patient_location', $data);
	}
	
	function Update_unit_patient_location($data)
	{
		$this->db->where('unit_patient_location_id',element('unit_patient_location_id', $data));
		$this->db->where('facility_id',$this->facility_id);
		
		return $this->db->update('unit_patient_location',$data);
	}
	
	function Delete_unit_patient_location()
	{
		$ret_val = $this->delete_record('unit_patient_location','unit_patient_location_id');
		return $ret_val;
	}
	/*
	 * Returns a list of current unit_patient_locations
	 * @todo must filter by logged in user
	 */
	function get_unit_patient_location_list()
	{
		$select_fields = "unit_patient_location_id
										 ,unit_patient_location
										 ,CASE active WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE '' END AS active";
		//Get the query results for the clinical unit_patient_locations
		$this->db->select($select_fields, false);
		$this->db->from('unit_patient_location');
		$this->db->where('facility_id',$this->facility_id);
		$this->db->order_by('unit_patient_location');
		$query = $this->db->get();
				
		return $query->result_array();
	}

	/*
	 * Returns a single unit_patient_location record based on unit_patient_location Id passed 
	 */
	function get_unit_patient_location_record($unit_patient_location_id)
	{
		$query = $this->db->limit(1)->get_where('unit_patient_location', array('unit_patient_location_id' => $unit_patient_location_id,
		 																		'facility_id'	=> $this->facility_id));
		return $query->row();
	}	
}

/* End of file unit_patient_location_model.php */
/* Location: ./system/application/models/unit_patient_location_model.php */